package July;

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import javax.jws.soap.SOAPBinding;
import java.util.Scanner;

public class Day0713 {
    //计算糖果
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int E = scanner.nextInt();//A-B
        int F = scanner.nextInt();///B-C
        int G = scanner.nextInt();//A+B
        int H = scanner.nextInt();//B+C
        int A = (E+G)/2;
        int B1 = (G-E)/2;
        int B2 = (F+H)/2;
        int C = (H-F)/2;
        if (B1 != B2)
            System.out.println("No");
        else
            System.out.println(A+" "+B1+" "+C);
    }


    //进制转换
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int M = scanner.nextInt();
        int N = scanner.nextInt();

        //关于16进制
        String s = "0123456789ABCDEF";

        //进位
        boolean f =false;

        if (M == 0)
            System.out.println("0");

        if (M<0){
            M = -M;
            f = true;
        }

        //构建输出
        StringBuffer stringBuffer = new StringBuffer();
        while (M!=0){
            stringBuffer.append(s.charAt(M%N));
            M = M/N;
        }

        if (f)
            stringBuffer.append("-");
        stringBuffer.reverse();
        System.out.println(stringBuffer);
    }
}
